/*
 *  Copyright (C) 2011 Matt Van Der Westhuizen <mattpwest@gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.chaoticengine.cgll.profile;

import java.util.ArrayList;
import org.chaoticengine.cgll.score.HighScoreList;
import org.chaoticengine.cgll.score.Score;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

/**
 * A collection of PlayerProfiles.
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
@Root(name="users")
public class Profiles {
    protected ArrayList<Profile> profiles = new ArrayList<Profile>();
    protected HighScoreList scores = null;

    public void addProfile(Profile p) {
        if (!profiles.contains(p)) {
            profiles.add(p);
        }
    }

    public boolean hasProfile(String name) {
        for (int i = 0; i < profiles.size(); i++) {
            if (profiles.get(i).getName().toUpperCase().equals(name.toUpperCase())) {
                return(true);
            }
        }

        return(false);
    }

    @ElementList(name="profiles", entry="profile", required=false)
    public void setProfiles(ArrayList<Profile> profiles) {
        this.profiles = profiles;
    }

    @ElementList(name="profiles", entry="profile", required=false)
    public ArrayList<Profile> getProfiles() {
        return(profiles);
    }

    @Element(name="highscores")
    public HighScoreList getHighScores() {
        if (scores == null) {
            scores = new HighScoreList();

            ArrayList<Score> scoreList = new ArrayList<Score>();

            Score s = new Score();
            s.setPlayer("Kara Thrace");
            s.setValue(10000);
            scoreList.add(s);

            s = new Score();
            s.setPlayer("Han Solo");
            s.setValue(8000);
            scoreList.add(s);

            s = new Score();
            s.setPlayer("Cybermage");
            s.setValue(6000);
            scoreList.add(s);

            scores.setHighScores(scoreList);
        }
        
        return(scores);
    }

    @Element(name="highscores")
    public void setHighScores(HighScoreList list) {
        this.scores = list;
    }
}
